﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kevin.Framework.Data.OrmMapping;

namespace Kevin.WindosControls.Test.Entity
{
    [Serializable]
    [TableMapping("Forms")]
    public class FormsInfo : EntityBase
    {
        #region Constructor

        public FormsInfo()
            : this("")
        { }
        public FormsInfo(string connectionKey)
            : base(connectionKey)
        { }

        #endregion

        #region Methods

        public FormsInfo Load(string formID)
        {
            this.ID = formID;
            List<FormsInfo> list = this.SelectedByProperties<FormsInfo>();
            return list[0];
        }

        static FormsInfo _instance;
        public static FormsInfo Instance
        {

            get
            {
                if (_instance == null)
                {
                    return new FormsInfo();
                }
                else
                {
                    return _instance;
                }
            }
        }

        #endregion

        #region Properties

        private string _id;
        /// <summary>
        /// ID
        /// </summary>		
        [FieldMapping("ID", PrimaryKey = true)]
        public string ID
        {
            get
            {
                return _id;
            }
            set
            {
                if (_id != value)
                {
                    base.OnPropertyChanged("ID", _id, value);
                    _id = value;
                }
            }
        }

        private string _text;
        /// <summary>
        /// Text
        /// </summary>		
        [FieldMapping("Text")]
        public string Text
        {
            get
            {
                return _text;
            }
            set
            {
                if (_text != value)
                {
                    base.OnPropertyChanged("Text", _text, value);
                    _text = value;
                }
            }
        }

        private string _layout;
        /// <summary>
        /// Layout
        /// </summary>		
        [FieldMapping("Layout")]
        public string Layout
        {
            get
            {
                return _layout;
            }
            set
            {
                if (_layout != value)
                {
                    base.OnPropertyChanged("Layout", _layout, value);
                    _layout = value;
                }
            }
        }
        List<InputItemInfo> _controls;
        public List<InputItemInfo> Controls
        {
            get
            {
                if (_controls == null)
                {
                    InputItemInfo item = new InputItemInfo();
                    item.FormID = this.ID;
                    _controls = item.SelectedByProperties<InputItemInfo>();
                }
                return _controls;
            }
            set {
                _controls = value;
            }
        }
        #endregion
    }
}
